import HTTP from '../util/http.js'

class ClassicModel extends HTTP {
  // 获取最新的期刊
  getLatest() {
    return new Promise((resolve, reject) => {
      this.request('/api/classic/get', {
        user: wx.getStorageSync('user').nickName
      }).then(res => {
        resolve(res)
      })
    })
  }
  // 喜欢
  isLike({id, type}) {
    return new Promise((resolve, reject)=> {
      this.request('/api/classic/like', {
        user: wx.getStorageSync('user').nickName,
        id,
        type
      }, 'POST').then(res => {
        resolve(res)
      })
    })
  }
  // 取消喜欢
  cancelLike({id, type}) {
    return new Promise((resolve, reject)=> {
      this.request('/api/classic/cancel', {
        user: wx.getStorageSync('user').nickName,
        id,
        type
      }, 'POST').then(res => {
        resolve(res)
      })
    })
  }
  // 上一期
  getPre(index) {
    return new Promise((resolve, reject)=> {
      this.request('/api/classic/getByIndex', {
        index,
        user: wx.getStorageSync('user').nickName
      }).then(res => {
        resolve(res)
      })
    })
  }
  // 获取喜欢信息
  getFavor(id, type) {
    return new Promise((resolve, reject) => {
      this.request('/api/classic/getFavor', {
        id,
        type,
        user: wx.getStorageSync('user').nickName
      }).then(res => {
        resolve(res)
      })
    })  
  }

  getMyFavor() {
    return new Promise((resolve, reject) => {
      this.request('/api/classic/myFavor', {
        user: wx.getStorageSync('user').nickName 
      }).then((res) => {
        resolve(res)
      })
    })
  }

  isFirst(index) {
    return index == 1 ? true : false
  }

  isLatest(index) {
      let latestIndex = wx.getStorageSync('latest')
      return latestIndex == index ? true : false
  }

  // getClassicById(id, type) {
  //   this.request('/api/classic/getClassicById', {
  //     id,
  //     type
  //   }).then(res => {
  //     resolve(res)
  //   })
  // }
}


export {
  ClassicModel
}
